package servlet;

import db.DB;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/deletecustomer")//访问的时候给一个地址,高于3.0版本的包才能这么配地址
public class deletecustomer extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setHeader("content-type", "text/html;charset=utf-8");
        int customerid = Integer.parseInt(req.getParameter("customerid"));
        HttpSession session=req.getSession();
        String message = null; //定义message变量
        String datapage = null;
        if (new DB().deletecustomer(customerid)) {
            datapage = "customer";
            session.setAttribute("datapage",datapage);
            return; }
        else {
            message = "删除失败！可能存在包含该供应商的订单";
            session.setAttribute("message",message);
            return;
        }
    }
}

